from connect.conn_mysql import Connect

class SaveCode(Connect):

    def save(self,phone,pass_word):
        '''保存用户的账号和验证码到数据库'''
        save_sql = '''
        insert into user(phone,password)
        values(%s,%s)
        '''
        self.insert(save_sql,(phone,pass_word))

    def send_sms(self):
        '''发送短信的函数'''
        return {
            'status':1,
            'errorCode':None,
            'errorMsg':None,
            'resultBody':'发送信息成功'
        } 

    def register(self,phone,phone_verify_code,pass_word):
        '''注册函数'''
        register_sql = '''
        select * from user where phone = %s and password=%s
        '''
        result = self.select_one(register_sql,(phone,phone_verify_code,pass_word))        
        # print(result)
        if not result==None:return{
            'status':1,
            'errorCode':None,
            'errorMsg':None,
            'resultBody':'注册成功'
            }
        else:
            return {
            'status':-1,
            'errorCode':404,
            'errorMsg':'没有你的号码或者是验证码错误',
            'resultBody':'注册失败'
            }
        
